package com.daryl.jcu_project1_creditscoreform;

import android.os.Bundle;
import android.preference.Preference;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class Display_form_personal_details2 extends Activity {
	public static final String TAG = Display_form_personal_details2.class
			.getName();
	/**
	 * @uml.property name="button_next"
	 * @uml.associationEnd readOnly="true"
	 */
	private variables vb = new variables();
	Button button_next;
	EditText usernametest;
	EditText faxNumberIDD;
	EditText faxNumber;
	EditText homePhoneNumberIDD;
	EditText homePhoneNumber;
	EditText workPhoneNumberIDD;
	EditText workPhoneNumber;
	EditText mobilePhoneNumberIDD;
	EditText mobilePhoneNumber;
	EditText emailAddress;
	EditText residentAddress;
	EditText residentPostalCode;
	EditText residentYears;
	EditText residentMonths;
	EditText specifyHere;
	EditText postalAddPostalCode;
	RadioGroup residentStatus;
	RadioGroup PostalAddDiffFromResidentAdd;
	RadioGroup PostalAddChangeLoanSettled;
	RadioGroup PreviousAdd;
	int x = 0;
	public String vFaxNumberIDD;
	public String vFaxNumber;
	public String vHomePhoneNumberIDD;
	public String vHomePhoneNumber;
	public String vWorkPhoneNumberIDD;
	public String vWorkPhoneNumber;
	public String vMobilePhoneNumberIDD;
	public String vMobilePhoneNumber;
	public String vEmailAddress;
	public String vResidentStatus;
	public String vResidentAddress;
	public String vResidentPostalCode;
	public String vResidentYears;
	public String vResidentMonths;
	public String vPostalAddDiffFromResidentAdd;
	public String vPostalAddDiffFromResidentAddBtn;
	public String vPostalAddPostalCode;
	public String vPostalAddChangeWhenLoanSettledBtn;
	public String vPostalAddChangeWhenLoanSettled;
	public String vPostalCodeChangeWhenLoanSettled;
	public String vPreviousAddBtn;
	public String vPreviousAddress;
	public String vPreviousAddressPostalCode;
	public String vPreviousAddressYears;
	public String vPreviousAddressMonths;

	// public int selected;
	public static int nextpage = 0;
	public static int backpage;

	// public static String retriveValue;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_display_form_personal_details2);
		getRadioBtnResidenStatus();
		getRadioBtnPostalAddDiffFromResidentAdd();
		getRadioBtnPostalAddChangeLoanSettled();
		getRadioBtnPreviousAdd();
		Display_form_personal_details dp = new Display_form_personal_details();
		System.out.println("next page number " + nextpage);
		if (dp.nextpage > 0) {
			System.out.println("next page 2 set " + dp.nextpage);
			setCustomerFaxNumberIDD();
			setCustomerFaxNumberIDD();
			setCustomerFaxNumber();
			setCustomerHomePhoneNumberIDD();
			setCustomerHomePhoneNumber();
			setCustomerWorkPhoneNumberIDD();
			setCustomerWorkPhoneNumber();
			setCustomerMobilePhoneNumberIDD();
			setCustomerMobilePhoneNumber();
			setCustomerEmailAddress();
			setRadioBtnResidenStatus();
			setCustomerCurrentAddress();
			setCustomerPostalCode();
			setCustomerResidentYears();
			setCustomerResidentMonths();
			setCustomerSepecifyHere();
			setRadioBtnPostalAddDiffFromResidentAdd();
			setCustomerPostalAddPostalCode();
			setRadioBtnPostalAddChangeLoanSettled();
			setCustomerPostalAddChangeWhenLoanSettled();
			setCustomerPostalCodeChangeWhenLoanSettled();
			setRadioBtnPreviousAdd();
			setPreviousAdd();
			setPreviousAddPostalCode();
			setPreviousAddDurationYears();
			setPreviousAddDurationMonths();
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(
				R.menu.activity_display_form_personal_details2, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/*
	 * public void resume(){
	 * 
	 * Log.i(TAG, "onResume()"); System.out.println("On Resume");
	 * setCustomerFaxNumberIDD(); setCustomerFaxNumber();
	 * setCustomerHomePhoneNumberIDD(); setCustomerHomePhoneNumber();
	 * setCustomerWorkPhoneNumberIDD(); setCustomerWorkPhoneNumber();
	 * setCustomerMobilePhoneNumberIDD(); setCustomerMobilePhoneNumber();
	 * setCustomerEmailAddress(); //setRadioBtnResidenStatus(); }
	 */

	public void buttonClickYes(View view) {
		LinearLayout ll1 = (LinearLayout) findViewById(R.id.llSpecifyNewAddressHere);
		ll1.setVisibility(View.VISIBLE);

		LinearLayout ll2 = (LinearLayout) findViewById(R.id.llSpecifyNewAddressPostcode);
		ll2.setVisibility(View.VISIBLE);
	}

	public void buttonClickNo(View view) {
		LinearLayout ll1 = (LinearLayout) findViewById(R.id.llSpecifyNewAddressHere);
		ll1.setVisibility(View.GONE);

		LinearLayout ll2 = (LinearLayout) findViewById(R.id.llSpecifyNewAddressPostcode);
		ll2.setVisibility(View.GONE);
	}

	public void postalAddressClickYes(View view) {
		LinearLayout ll1 = (LinearLayout) findViewById(R.id.llSpecifyHere);
		ll1.setVisibility(View.VISIBLE);

		LinearLayout ll2 = (LinearLayout) findViewById(R.id.llPostalAddressPostCode);
		ll2.setVisibility(View.VISIBLE);
	}

	public void postalAddressClickNo(View view) {
		LinearLayout ll1 = (LinearLayout) findViewById(R.id.llSpecifyHere);
		ll1.setVisibility(View.GONE);

		LinearLayout ll2 = (LinearLayout) findViewById(R.id.llPostalAddressPostCode);
		ll2.setVisibility(View.GONE);
	}

	public void nextPage(View view) {
		 Intent intent_next = new Intent (this,
		 Display_form_employment_details.class);
		 startActivity(intent_next);
		 int retriveValue = 0;

		System.out.println("type of applicant1 " + vb.setTypeOfApplicant());
		System.out.println("existing customer1 " + vb.setExistingCustomer());
		System.out.println("customer title1 " + vb.setCustomerTitle());
		System.out.println("customer login1 " + vb.setUserLoginName());
		System.out.println("customer number1 " + vb.setCustomerNumber());
		System.out.println("customer years with hsbc1 "
				+ vb.setTimeWithHSBCYears());
		System.out.println("customer months with hsbc1 "
				+ vb.setTimeWithHSBCMonths());

		Display_form_personal_details dp = new Display_form_personal_details();
		methods md = new methods();
		System.out.println("back 2");
		getCustomerFaxNumberIDD();
		System.out.println("back 2");
		getCustomerFaxNumber();
		getCustomerHomePhoneNumberIDD();
		getCustomerHomePhoneNumber();
		getCustomerWorkPhoneNumberIDD();
		getCustomerWorkPhoneNumber();
		getCustomerMobilePhoneNumberIDD();
		getCustomerMobilePhoneNumber();
		getCustomerEmailAddress();
		getRadioBtnResidenStatus();
		getCustomerCurrentAddress();
		getCustomerPostalCode();
		getCustomerResidentYears();
		getCustomerResidentMonths();
		getRadioBtnPostalAddDiffFromResidentAdd();
		
		
		
		getRadioBtnPostalAddChangeLoanSettled();
		
		getRadioBtnPreviousAdd();
		
		//this is to check if answer is no if current add is more then 3 years
		
			
		
		
		
		
		if(md.retriveShareIntPreference(this,retriveValue,"previousPage2")>0){ 
		nextpage++;
		
		try {
		if (md.retriveSharePreference(this,vPreviousAddBtn, "dPreviousAddBtn" ).equals("No")) {
			getPreviousAdd();
			getPreviousAddPostalCode();
			getPreviousAddDurationYears();
			getPreviousAddDurationMonths();
		}
		else if (md.retriveSharePreference(this,vPreviousAddBtn, "dPreviousAddBtn" ).equals("Yes")) {
			getPreviousAddNull();
			getPreviousAddPostalCodeNull();
			getPreviousAddDurationYearsNull();
			getPreviousAddDurationMonthsNull();
		}
		
		} catch (NullPointerException ex){
			System.out.println("null 1");
		}
		}
		
		
				
	}

	public void previousPage(View view) {
		Intent intent_previous = new Intent(this,
				Display_form_personal_details.class);
		onBackPressed();
		Display_form_personal_details dp = new Display_form_personal_details();
		methods md = new methods();
		System.out.println("back 2");
		getCustomerFaxNumberIDD();
		System.out.println("back 2");
		getCustomerFaxNumber();
		getCustomerHomePhoneNumberIDD();
		getCustomerHomePhoneNumber();
		getCustomerWorkPhoneNumberIDD();
		getCustomerWorkPhoneNumber();
		getCustomerMobilePhoneNumberIDD();
		getCustomerMobilePhoneNumber();
		getCustomerEmailAddress();
		getRadioBtnResidenStatus();
		getCustomerCurrentAddress();
		getCustomerPostalCode();
		getCustomerResidentYears();
		getCustomerResidentMonths();
		getRadioBtnPostalAddDiffFromResidentAdd();
		
		md.editorShareIntPreferences(this, "previousPage1", 1);
		
		
		
		getRadioBtnPostalAddChangeLoanSettled();
		getRadioBtnPreviousAdd();
		
		//this is to check if answer is no if current add is more then 3 years
		
		if (md.retriveSharePreference(this,vPreviousAddBtn, "dPreviousAddBtn" ).equals("No")) {
			getPreviousAdd();
			getPreviousAddPostalCode();
			getPreviousAddDurationYears();
			getPreviousAddDurationMonths();
		}
		else if (md.retriveSharePreference(this,vPreviousAddBtn, "dPreviousAddBtn" ).equals("Yes")) {
			getPreviousAddNull();
			getPreviousAddPostalCodeNull();
			getPreviousAddDurationYearsNull();
			getPreviousAddDurationMonthsNull();
		}
	

	}

	public void previousAddressQuestionYes(View view) {
		TextView tv1 = (TextView) findViewById(R.id.tvPreviousAddress);
		tv1.setVisibility(View.GONE);

		EditText et1 = (EditText) findViewById(R.id.etPreviousAddress);
		et1.setVisibility(View.GONE);

		LinearLayout ll1 = (LinearLayout) findViewById(R.id.llPreviousAddressPostcode);
		ll1.setVisibility(View.GONE);

		TextView tv2 = (TextView) findViewById(R.id.tvTimeAtPreviousAddress);
		tv2.setVisibility(View.GONE);

		LinearLayout ll2 = (LinearLayout) findViewById(R.id.llTimeAtPreviousAddress);
		ll2.setVisibility(View.GONE);
	}

	public void previousAddressQuestionNo(View view) {
		TextView tv1 = (TextView) findViewById(R.id.tvPreviousAddress);
		tv1.setVisibility(View.VISIBLE);

		EditText et1 = (EditText) findViewById(R.id.etPreviousAddress);
		et1.setVisibility(View.VISIBLE);

		LinearLayout ll1 = (LinearLayout) findViewById(R.id.llPreviousAddressPostcode);
		ll1.setVisibility(View.VISIBLE);

		TextView tv2 = (TextView) findViewById(R.id.tvTimeAtPreviousAddress);
		tv2.setVisibility(View.VISIBLE);

		LinearLayout ll2 = (LinearLayout) findViewById(R.id.llTimeAtPreviousAddress);
		ll2.setVisibility(View.VISIBLE);
	}

	// get customer fax number IDD
	public void getCustomerFaxNumberIDD() {
		methods md = new methods();
		faxNumberIDD = (EditText) findViewById(R.id.etFaxNoIDD);
		vFaxNumberIDD = faxNumberIDD.getText().toString();
		md.editorSharePreferences(this, "dFaxNumberIDD", vFaxNumberIDD);
		System.out.println("retrive value1 fax idd" + vFaxNumberIDD);
	}

	public void setCustomerFaxNumberIDD() {

		methods md = new methods();

		faxNumberIDD = (EditText) findViewById(R.id.etFaxNoIDD);
		faxNumberIDD.setText(md.retriveSharePreference(this, "vFaxNumberIDD",
				"dFaxNumberIDD"));
		System.out.println("set fax number idd "
				+ md.retriveSharePreference(this, "vFaxNumberIDD",
						"dFaxNumberIDD"));

	}

	// get customer fax number
	public void getCustomerFaxNumber() {

		faxNumber = (EditText) findViewById(R.id.etFaxNo);
		vFaxNumber = faxNumber.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dFaxNumber", vFaxNumber);
	}

	public void setCustomerFaxNumber() {

		faxNumber = (EditText) findViewById(R.id.etFaxNo);
		methods md = new methods();
		faxNumber.setText(md.retriveSharePreference(this, "vFaxNumber",
				"dFaxNumber"));
	}

	// get customer ome hphone number IDD
	public void getCustomerHomePhoneNumberIDD() {
		methods md = new methods();
		homePhoneNumberIDD = (EditText) findViewById(R.id.etHousePNoIDD);
		vHomePhoneNumberIDD = homePhoneNumberIDD.getText().toString();
		md.editorSharePreferences(this, "dHomePhoneNumberIDD",
				vHomePhoneNumberIDD);
		System.out.println("retrive value1 " + vHomePhoneNumberIDD);
	}

	public void setCustomerHomePhoneNumberIDD() {

		methods md = new methods();

		homePhoneNumberIDD = (EditText) findViewById(R.id.etHousePNoIDD);
		homePhoneNumberIDD.setText(md.retriveSharePreference(this,
				"vHomePhoneNumberIDD", "dHomePhoneNumberIDD"));

	}

	// get customer home phone number
	public void getCustomerHomePhoneNumber() {

		homePhoneNumber = (EditText) findViewById(R.id.etHousePNo);
		vHomePhoneNumber = homePhoneNumber.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dHomePhomeNumber", vHomePhoneNumber);
	}

	public void setCustomerHomePhoneNumber() {

		homePhoneNumber = (EditText) findViewById(R.id.etHousePNo);
		methods md = new methods();
		homePhoneNumber.setText(md.retriveSharePreference(this,
				"vHomePhoneNumber", "dHomePhomeNumber"));
	}

	// get customer work phone number IDD
	public void getCustomerWorkPhoneNumberIDD() {
		methods md = new methods();
		workPhoneNumberIDD = (EditText) findViewById(R.id.etWorkPNoIDD);
		vWorkPhoneNumberIDD = workPhoneNumberIDD.getText().toString();
		md.editorSharePreferences(this, "dWorkPhoneNumberIDD",
				vWorkPhoneNumberIDD);
		System.out.println("retrive value1 " + vWorkPhoneNumberIDD);
	}

	public void setCustomerWorkPhoneNumberIDD() {

		methods md = new methods();

		workPhoneNumberIDD = (EditText) findViewById(R.id.etWorkPNoIDD);
		workPhoneNumberIDD.setText(md.retriveSharePreference(this,
				"vWorkPhoneNumberIDD", "dWorkPhoneNumberIDD"));

	}

	// get customer work phone number
	public void getCustomerWorkPhoneNumber() {

		workPhoneNumber = (EditText) findViewById(R.id.etWorkPNo);
		vWorkPhoneNumber = workPhoneNumber.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dWorkPhomeNumberIDD", vWorkPhoneNumber);
	}

	public void setCustomerWorkPhoneNumber() {

		workPhoneNumber = (EditText) findViewById(R.id.etWorkPNo);
		methods md = new methods();
		workPhoneNumber.setText(md.retriveSharePreference(this,
				"vWorkPhoneNumber", "dWorkPhomeNumberIDD"));
	}

	// get customer work phone number IDD
	public void getCustomerMobilePhoneNumberIDD() {
		methods md = new methods();
		mobilePhoneNumberIDD = (EditText) findViewById(R.id.etMobilePNoIDD);
		vMobilePhoneNumberIDD = mobilePhoneNumberIDD.getText().toString();
		md.editorSharePreferences(this, "dMobilePhoneNumberIDD",
				vMobilePhoneNumberIDD);
		System.out.println("retrive value3 " + vMobilePhoneNumberIDD);
	}

	public void setCustomerMobilePhoneNumberIDD() {

		methods md = new methods();

		mobilePhoneNumberIDD = (EditText) findViewById(R.id.etMobilePNoIDD);
		mobilePhoneNumberIDD.setText(md.retriveSharePreference(this,
				"vMobilePhoneNumberIDD", "dMobilePhoneNumberIDD"));

	}

	// get customer mobile phone number
	public void getCustomerMobilePhoneNumber() {

		mobilePhoneNumber = (EditText) findViewById(R.id.etMobilePNo);
		vMobilePhoneNumber = mobilePhoneNumber.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dMobilePhoneNumber",
				vMobilePhoneNumber);
	}

	public void setCustomerMobilePhoneNumber() {

		mobilePhoneNumber = (EditText) findViewById(R.id.etMobilePNo);
		methods md = new methods();
		mobilePhoneNumber.setText(md.retriveSharePreference(this,
				"vMobilePhoneNumber", "dMobilePhoneNumber"));
	}

	// get customer email address
	public void getCustomerEmailAddress() {

		emailAddress = (EditText) findViewById(R.id.etEaddress);
		vEmailAddress = emailAddress.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dEmailAddress", vEmailAddress);
	}

	public void setCustomerEmailAddress() {

		emailAddress = (EditText) findViewById(R.id.etEaddress);
		methods md = new methods();
		emailAddress.setText(md.retriveSharePreference(this, "vEmailAddress",
				"dEmailAddress"));
	}

	// get value in resident status radio grp
	public void getRadioBtnResidenStatus() {

		System.out.println("Test 121 ");
		// Gets a reference to our radio group
		// rgExistingCustomer is the name of our radio group
		residentStatus = (RadioGroup) findViewById(R.id.rgResidentialStatus1stRow);
		residentStatus
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {

					public void onCheckedChanged(RadioGroup group, int checkedId) {
						System.out.println("Test 122 ");
						methods md = new methods();
						variables vb = new variables();
						// Returns an integer which represents the selected
						// radio button's ID
						int selected = residentStatus.getCheckedRadioButtonId();

						System.out.println(" get tested 1 " + selected);

						// Gets a reference to our "selected" radio button
						RadioButton residentStatusBtn = (RadioButton) findViewById(selected);
						// bring the selected button to variable class

						vResidentStatus = residentStatusBtn.getText()
								.toString();

						SharedPreferences preferences = getSharedPreferences(
								"Mb4Me", 0);
						SharedPreferences.Editor editor = preferences.edit();
						editor.putString("dResidentStatus", vResidentStatus);
						editor.putInt("dResidentStatusInt", selected);
						editor.commit();
						System.out.println(" get tested 1.2 " + selected);
					}

				});

	}

	// set value in resident status radio grp
	public void setRadioBtnResidenStatus() {

		// Gets a reference to our radio group
		// rgExistingCustomer is the name of our radio group
		residentStatus = (RadioGroup) findViewById(R.id.rgResidentialStatus1stRow);

		methods md = new methods();
		variables vb = new variables();
		int selected = 0;
		// Returns an integer which represents the selected
		// radio button's ID
		// selected = residentStatus
		// .getCheckedRadioButtonId();

		System.out.println("tested1 " + selected);

		SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
		int retriveValue = md.retriveShareIntPreference(this, selected,
				"dResidentStatusInt");

		System.out.println("tested2.1 " + retriveValue);
		try{
		// sets a reference to our "selected" radio button
		RadioButton residentStatusBtn = (RadioButton) findViewById(retriveValue);
		residentStatusBtn.setChecked(true);
		}
		catch (NullPointerException ex){
			System.out.println("null 1");
		}
	}

	// get customer current address
	public void getCustomerCurrentAddress() {

		residentAddress = (EditText) findViewById(R.id.etCurrentResidentialAddress);
		vResidentAddress = residentAddress.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dResidentAddress", vResidentAddress);
	}

	public void setCustomerCurrentAddress() {

		residentAddress = (EditText) findViewById(R.id.etCurrentResidentialAddress);
		methods md = new methods();
		residentAddress.setText(md.retriveSharePreference(this,
				"vResidentAddress", "dResidentAddress"));
	}

	// get customer postal code
	public void getCustomerPostalCode() {

		residentPostalCode = (EditText) findViewById(R.id.etCurrentResidentialAddressPostcode);
		vResidentPostalCode = residentPostalCode.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dResidentPostalCode",
				vResidentPostalCode);
	}

	public void setCustomerPostalCode() {

		residentPostalCode = (EditText) findViewById(R.id.etCurrentResidentialAddressPostcode);
		methods md = new methods();
		residentPostalCode.setText(md.retriveSharePreference(this,
				"vResidentPostalCode", "dResidentPostalCode"));
	}

	// get customer resident years
	public void getCustomerResidentYears() {

		residentYears = (EditText) findViewById(R.id.etYears);
		vResidentYears = residentYears.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dResidentYears", vResidentYears);
	}

	public void setCustomerResidentYears() {

		residentYears = (EditText) findViewById(R.id.etYears);
		methods md = new methods();
		residentYears.setText(md.retriveSharePreference(this, "vResidentYears",
				"dResidentYears"));
	}

	// get customer resident months
	public void getCustomerResidentMonths() {

		residentMonths = (EditText) findViewById(R.id.etMonths);
		vResidentMonths = residentMonths.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dResidentMonths", vResidentMonths);
	}

	public void setCustomerResidentMonths() {

		residentMonths = (EditText) findViewById(R.id.etMonths);
		methods md = new methods();
		residentMonths.setText(md.retriveSharePreference(this,
				"vResidentMonths", "dResidentMonths"));
	}

	// get value in postal add different to residental add radio grp
	public void getRadioBtnPostalAddDiffFromResidentAdd() {

		System.out.println("Test 121 ");
		// Gets a reference to our radio group
		// rgExistingCustomer is the name of our radio group
		PostalAddDiffFromResidentAdd = (RadioGroup) findViewById(R.id.rgPostalAddress);
		PostalAddDiffFromResidentAdd
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {

					public void onCheckedChanged(RadioGroup group, int checkedId) {
						System.out.println("Test 122 ");
						methods md = new methods();
						variables vb = new variables();
						// Returns an integer which represents the selected
						// radio button's ID
						int selected = PostalAddDiffFromResidentAdd
								.getCheckedRadioButtonId();

						System.out.println(" get tested 1 " + selected);

						// Gets a reference to our "selected" radio button
						RadioButton residentStatusBtn = (RadioButton) findViewById(selected);
						// bring the selected button to variable class

						vPostalAddDiffFromResidentAddBtn = residentStatusBtn
								.getText().toString();

						SharedPreferences preferences = getSharedPreferences(
								"Mb4Me", 0);
						SharedPreferences.Editor editor = preferences.edit();
						editor.putString("dPostalAddDiffFromResidentAddBtn", vPostalAddDiffFromResidentAddBtn); //store the radio btn text
						editor.putInt("dPostalAddDiffFromResidentAddInt", selected);							// store the radio btn selected integer
						editor.commit();
						System.out.println(" get tested 1.2 " + selected);
					}

				});

	}

	// set value in resident status radio grp
	public void setRadioBtnPostalAddDiffFromResidentAdd() {

		// Gets a reference to our radio group
		// rgExistingCustomer is the name of our radio group
		PostalAddDiffFromResidentAdd = (RadioGroup) findViewById(R.id.rgPostalAddress);

		methods md = new methods();
		variables vb = new variables();
		int selected = 0;
		// Returns an integer which represents the selected
		// radio button's ID
		// selected = residentStatus
		// .getCheckedRadioButtonId();

		System.out.println("tested1 " + selected);

		SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
		int retriveValue = md.retriveShareIntPreference(this, selected,
				"dPostalAddDiffFromResidentAddInt");

		System.out.println("tested2.2 " + retriveValue);
		try {
		// sets a reference to our "selected" radio button
		RadioButton PostalAddDiffFromResidentAddBtn = (RadioButton) findViewById(retriveValue);
		PostalAddDiffFromResidentAddBtn.setChecked(true);
		System.out.println("vPostalAddDiffFromResidentAdd1 " + md.retriveSharePreference(this,vPostalAddDiffFromResidentAddBtn, "dPostalAddDiffFromResidentAddBtn" ));
		
		//check condition for yes or not
		if (md.retriveSharePreference(this,vPostalAddDiffFromResidentAddBtn, "dPostalAddDiffFromResidentAddBtn" ).equals("Yes")) {
			System.out.println("vPostalAddDiffFromResidentAdd2 " + vPostalAddDiffFromResidentAdd);
			//this is to visible the addition edit text
			LinearLayout ll1 = (LinearLayout) findViewById(R.id.llSpecifyHere);
			ll1.setVisibility(View.VISIBLE);

			LinearLayout ll2 = (LinearLayout) findViewById(R.id.llPostalAddressPostCode);
			ll2.setVisibility(View.VISIBLE);
		} else {
			
			//this is to disable the additional edit text
			LinearLayout ll1 = (LinearLayout) findViewById(R.id.llSpecifyHere);
			ll1.setVisibility(View.GONE);

			LinearLayout ll2 = (LinearLayout) findViewById(R.id.llPostalAddressPostCode);
			ll2.setVisibility(View.GONE);
		}
		} catch (NullPointerException ex ){
			System.out.print(" null 2 " );
		}
	}

	// get customer resident postal address
	public void getCustomerSepecifyHere() {

		specifyHere = (EditText) findViewById(R.id.etPostalAddress);
		vPostalAddDiffFromResidentAdd = specifyHere.getText().toString();
		methods md = new methods();
		md.editorSharePreferences(this, "dPostalAddDiffFromResidentAdd",
				vPostalAddDiffFromResidentAdd);
		
		//this is to check if answer is yes for postal add diff from resdient add and get the value insert by user

				if (md.retriveSharePreference(this,vPostalAddDiffFromResidentAddBtn, "dPostalAddDiffFromResidentAddBtn" ).equals("Yes")) {
					getCustomerSepecifyHere();
					
					
				} 
				else if (md.retriveSharePreference(this,vPostalAddDiffFromResidentAddBtn, "dPostalAddDiffFromResidentAddBtn" ).equals("No")){
					 getCustomerSepecifyHereNull();
					 
				}
	}

	public void getCustomerSepecifyHereNull() {

		
		methods md = new methods();
		md.editorSharePreferences(this, "dPostalAddDiffFromResidentAdd",
				null);
	}

	public void setCustomerSepecifyHere() {

		specifyHere = (EditText) findViewById(R.id.etPostalAddress);
		methods md = new methods();
		specifyHere.setText(md.retriveSharePreference(this,
				"vPostalAddDiffFromResidentAdd",
				"dPostalAddDiffFromResidentAdd"));
	
	}
	
	
	// get customer resident postal code
		public void getCustomerPostalAddPostalCode() {

			postalAddPostalCode = (EditText) findViewById(R.id.etPostalAddressPostCode);
			vPostalAddPostalCode = postalAddPostalCode.getText().toString();
			methods md = new methods();
			md.editorSharePreferences(this, "dPostalAddPostalCode",
					vPostalAddPostalCode);
			
			if (md.retriveSharePreference(this,vPostalAddDiffFromResidentAddBtn, "dPostalAddDiffFromResidentAddBtn" ).equals("Yes")) {
				
				getCustomerPostalAddPostalCode();
				
			} 
			else if (md.retriveSharePreference(this,vPostalAddDiffFromResidentAddBtn, "dPostalAddDiffFromResidentAddBtn" ).equals("No")){
				
				 getCustomerPostalAddPostalCodeNull();
			}
		}

		public void getCustomerPostalAddPostalCodeNull() {

			
			methods md = new methods();
			md.editorSharePreferences(this, "dPostalAddPostalCode",
					null);
		}

		public void setCustomerPostalAddPostalCode() {

			postalAddPostalCode = (EditText) findViewById(R.id.etPostalAddressPostCode);
			methods md = new methods();
			postalAddPostalCode.setText(md.retriveSharePreference(this,
					"vPostalAddPostalCode",
					"dPostalAddPostalCode"));
		
		}
		
		
		// get value in postal add change when loan settled
		public void getRadioBtnPostalAddChangeLoanSettled() {

			System.out.println("Test 121 ");
			// Gets a reference to our radio group
			// rgExistingCustomer is the name of our radio group
			PostalAddChangeLoanSettled = (RadioGroup) findViewById(R.id.rgChangeAddress);
			PostalAddChangeLoanSettled
					.setOnCheckedChangeListener(new OnCheckedChangeListener() {

						public void onCheckedChanged(RadioGroup group, int checkedId) {
							System.out.println("Test 122 ");
							methods md = new methods();
							variables vb = new variables();
							// Returns an integer which represents the selected
							// radio button's ID
							int selected = PostalAddChangeLoanSettled
									.getCheckedRadioButtonId();

							System.out.println(" get tested 1.31 " + selected);

							// Gets a reference to our "selected" radio button
							RadioButton residentStatusBtn = (RadioButton) findViewById(selected);
							// bring the selected button to variable class

							vPostalAddChangeWhenLoanSettledBtn = residentStatusBtn
									.getText().toString();

							SharedPreferences preferences = getSharedPreferences(
									"Mb4Me", 0);
							SharedPreferences.Editor editor = preferences.edit();
							editor.putString("dPostalAddChangeWhenLoanSettledBtn", vPostalAddChangeWhenLoanSettledBtn); //store the radio btn text
							editor.putInt("dPostalAddChangeLoanSettledInt", selected);							// store the radio btn selected integer
							editor.commit();
							System.out.println(" get tested 1.32 " + selected);
						}

					});

		}

		// set value in resident status radio grp
		public void setRadioBtnPostalAddChangeLoanSettled() {

			// Gets a reference to our radio group
			// rgExistingCustomer is the name of our radio group
			PostalAddChangeLoanSettled = (RadioGroup) findViewById(R.id.rgChangeAddress);

			methods md = new methods();
			variables vb = new variables();
			int selected = 0;
			// Returns an integer which represents the selected
			// radio button's ID
			// selected = residentStatus
			// .getCheckedRadioButtonId();

			System.out.println("tested1 " + selected);

			SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
			int retriveValue = md.retriveShareIntPreference(this, selected,
					"dPostalAddChangeLoanSettledInt");

			System.out.println("tested2.3 " + retriveValue);
			try {
			// sets a reference to our "selected" radio button
			RadioButton PostalAddChangeLoanSettledBtn = (RadioButton) findViewById(retriveValue);
			PostalAddChangeLoanSettledBtn.setChecked(true);
			System.out.println("vPostalAddChangeLoanSettledBtn " + md.retriveSharePreference(this,vPostalAddChangeWhenLoanSettledBtn, "dPostalAddChangeWhenLoanSettledBtn" ));
			
			//check condition for yes or not
			if (md.retriveSharePreference(this,vPostalAddChangeWhenLoanSettledBtn, "dPostalAddChangeWhenLoanSettledBtn" ).equals("Yes")) {
				System.out.println("vPostalAddChangeLoanSettledBtn " + vPostalAddChangeWhenLoanSettledBtn);
				//this is to visible the addition edit text
				LinearLayout ll1 = (LinearLayout) findViewById(R.id.llSpecifyNewAddressHere);
				ll1.setVisibility(View.VISIBLE);

				LinearLayout ll2 = (LinearLayout) findViewById(R.id.llSpecifyNewAddressPostcode);
				ll2.setVisibility(View.VISIBLE);
			} else {
				
				//this is to disable the additional edit text
				LinearLayout ll1 = (LinearLayout) findViewById(R.id.llSpecifyNewAddressHere);
				ll1.setVisibility(View.GONE);

				LinearLayout ll2 = (LinearLayout) findViewById(R.id.llSpecifyNewAddressPostcode);
				ll2.setVisibility(View.GONE);
			}
			} catch (NullPointerException ex ){
				System.out.print(" null 2 " );
			}
		}
		
		// get customer resident postal address when loan settled
		public void getCustomerPostalAddChangeWhenLoanSettled() {

			specifyHere = (EditText) findViewById(R.id.etSpecifyNewAddress);
			vPostalAddChangeWhenLoanSettled = specifyHere.getText().toString();
			methods md = new methods();
			md.editorSharePreferences(this, "dPostalAddChangeWhenLoanSettled",
					vPostalAddChangeWhenLoanSettled);
			
			//this is to check if answer is yes if postal will change after loan is settled
			if (md.retriveSharePreference(this,vPostalAddChangeWhenLoanSettledBtn, "dPostalAddChangeWhenLoanSettledBtn" ).equals("Yes")) {
				getCustomerPostalAddChangeWhenLoanSettled();
				
			}
			else if (md.retriveSharePreference(this,vPostalAddChangeWhenLoanSettledBtn, "dPostalAddChangeWhenLoanSettledBtn" ).equals("No")){
				getCustomerPostalAddChangeWhenLoanSettledNull();
				
			}
			
			
		}

		public void getCustomerPostalAddChangeWhenLoanSettledNull() {

			
			methods md = new methods();
			md.editorSharePreferences(this, "dPostalAddChangeWhenLoanSettled",
					null);
		}

		public void setCustomerPostalAddChangeWhenLoanSettled() {

			specifyHere = (EditText) findViewById(R.id.etSpecifyNewAddress);
			methods md = new methods();
			specifyHere.setText(md.retriveSharePreference(this,
					"vPostalAddChangeWhenLoanSettled",
					"dPostalAddChangeWhenLoanSettled"));
			
			
		
		}
		
		
		// get customer resident postal code when loan settled
				public void getCustomerPostalCodeChangeWhenLoanSettled() {

					specifyHere = (EditText) findViewById(R.id.etSpecifyNewAddressPostcode);
					vPostalCodeChangeWhenLoanSettled = specifyHere.getText().toString();
					methods md = new methods();
					md.editorSharePreferences(this, "dPostalCodeChangeWhenLoanSettled",
							vPostalCodeChangeWhenLoanSettled);
					
					//this is to check if answer is yes if postal will change after loan is settled
					if (md.retriveSharePreference(this,vPostalAddChangeWhenLoanSettledBtn, "dPostalAddChangeWhenLoanSettledBtn" ).equals("Yes")) {
						
						getCustomerPostalCodeChangeWhenLoanSettled();
					}
					else if (md.retriveSharePreference(this,vPostalAddChangeWhenLoanSettledBtn, "dPostalAddChangeWhenLoanSettledBtn" ).equals("No")){
						
						getCustomerPostalCodeChangeWhenLoanSettledNull();
					}
				}

				public void getCustomerPostalCodeChangeWhenLoanSettledNull() {

					
					methods md = new methods();
					md.editorSharePreferences(this, "dPostalCodeChangeWhenLoanSettled",
							null);
				}

				public void setCustomerPostalCodeChangeWhenLoanSettled() {

					specifyHere = (EditText) findViewById(R.id.etSpecifyNewAddressPostcode);
					methods md = new methods();
					specifyHere.setText(md.retriveSharePreference(this,
							"vPostalCodeChangeWhenLoanSettled",
							"dPostalCodeChangeWhenLoanSettled"));
				
				}
				
				
				
				// get value in postal add change when loan settled
				public void getRadioBtnPreviousAdd() {

					System.out.println("Test 121 ");
					// Gets a reference to our radio group
					// rgExistingCustomer is the name of our radio group
					PreviousAdd= (RadioGroup) findViewById(R.id.rgPreviousAddressQuestion);
					PreviousAdd
							.setOnCheckedChangeListener(new OnCheckedChangeListener() {

								public void onCheckedChanged(RadioGroup group, int checkedId) {
									System.out.println("Test 122 ");
									methods md = new methods();
									variables vb = new variables();
									// Returns an integer which represents the selected
									// radio button's ID
									int selected = PreviousAdd
											.getCheckedRadioButtonId();

									System.out.println(" get tested 1.31 " + selected);

									// Gets a reference to our "selected" radio button
									RadioButton residentStatusBtn = (RadioButton) findViewById(selected);
									// bring the selected button to variable class

									vPreviousAddBtn = residentStatusBtn
											.getText().toString();

									SharedPreferences preferences = getSharedPreferences(
											"Mb4Me", 0);
									SharedPreferences.Editor editor = preferences.edit();
									editor.putString("dPreviousAddBtn", vPreviousAddBtn); //store the radio btn text
									editor.putInt("dPreviousAddInt", selected);							// store the radio btn selected integer
									editor.commit();
									System.out.println(" get tested 1.32 " + selected);
								}

							});

				}

				// set value in resident status radio grp
				public void setRadioBtnPreviousAdd() {

					// Gets a reference to our radio group
					// rgExistingCustomer is the name of our radio group
					PreviousAdd = (RadioGroup) findViewById(R.id.rgPreviousAddressQuestion);

					methods md = new methods();
					variables vb = new variables();
					int selected = 0;
					// Returns an integer which represents the selected
					// radio button's ID
					// selected = residentStatus
					// .getCheckedRadioButtonId();

					System.out.println("tested1 " + selected);

					SharedPreferences preferences = getSharedPreferences("Mb4Me", 0);
					int retriveValue = md.retriveShareIntPreference(this, selected,
							"dPreviousAddInt");

					System.out.println("tested2.4 " + retriveValue);
					try {
					// sets a reference to our "selected" radio button
					RadioButton PostalAddChangeLoanSettledBtn = (RadioButton) findViewById(retriveValue);
					PostalAddChangeLoanSettledBtn.setChecked(true);
					System.out.println("vPreviousAddBtn " + md.retriveSharePreference(this,vPreviousAddBtn, "dPreviousAddBtn" ));
					
					
					
					//check condition for yes or not
					if (md.retriveSharePreference(this,vPreviousAddBtn, "dPreviousAddBtn" ).equals("Yes")) {
						System.out.println("vPreviousAddBtn " + vPreviousAddBtn);
						//this is to visible the addition edit text
						TextView tv1 = (TextView) findViewById(R.id.tvPreviousAddress);
						tv1.setVisibility(View.GONE);

						EditText et1 = (EditText) findViewById(R.id.etPreviousAddress);
						et1.setVisibility(View.GONE);

						LinearLayout ll1 = (LinearLayout) findViewById(R.id.llPreviousAddressPostcode);
						ll1.setVisibility(View.GONE);

						TextView tv2 = (TextView) findViewById(R.id.tvTimeAtPreviousAddress);
						tv2.setVisibility(View.GONE);

						LinearLayout ll2 = (LinearLayout) findViewById(R.id.llTimeAtPreviousAddress);
						ll2.setVisibility(View.GONE);
					} else {
						
						//this is to disable the additional edit text
						TextView tv1 = (TextView) findViewById(R.id.tvPreviousAddress);
						tv1.setVisibility(View.VISIBLE);

						EditText et1 = (EditText) findViewById(R.id.etPreviousAddress);
						et1.setVisibility(View.VISIBLE);

						LinearLayout ll1 = (LinearLayout) findViewById(R.id.llPreviousAddressPostcode);
						ll1.setVisibility(View.VISIBLE);

						TextView tv2 = (TextView) findViewById(R.id.tvTimeAtPreviousAddress);
						tv2.setVisibility(View.VISIBLE);

						LinearLayout ll2 = (LinearLayout) findViewById(R.id.llTimeAtPreviousAddress);
						ll2.setVisibility(View.VISIBLE);
					}
					
					} catch (NullPointerException ex ){
						System.out.print(" null 2 " );
					}
					
				}
				
				
				// get customer resident  address for not more then 3 years
				public void getPreviousAdd() {

					specifyHere = (EditText) findViewById(R.id.etPreviousAddress);
					vPreviousAddress = specifyHere.getText().toString();
					methods md = new methods();
					md.editorSharePreferences(this, "dPreviousAddress",
							vPreviousAddress);
					
					
				}

				public void getPreviousAddNull() {

					
					methods md = new methods();
					md.editorSharePreferences(this, "dPreviousAddress",
							null);
				}

				public void setPreviousAdd() {

					specifyHere = (EditText) findViewById(R.id.etPreviousAddress);
					methods md = new methods();
					specifyHere.setText(md.retriveSharePreference(this,
							"vPreviousAddress",
							"dPreviousAddress"));
				
				}
				
				
				// get customer resident postal code for not more then 3 Years
				public void getPreviousAddPostalCode() {

					specifyHere = (EditText) findViewById(R.id.etPreviousAddressPostcode);
					vPreviousAddressPostalCode = specifyHere.getText().toString();
					methods md = new methods();
					md.editorSharePreferences(this, "dPreviousAddressPostalCode",
							vPreviousAddressPostalCode);
				}

				public void getPreviousAddPostalCodeNull() {

					
					methods md = new methods();
					md.editorSharePreferences(this, "dPreviousAddressPostalCode",
							null);
				}

				public void setPreviousAddPostalCode() {

					specifyHere = (EditText) findViewById(R.id.etPreviousAddressPostcode);
					methods md = new methods();
					specifyHere.setText(md.retriveSharePreference(this,
							"vPreviousAddressPostalCode",
							"dPreviousAddressPostalCode"));
				
				}
				
				
				// get customer resident duration years for not more then 3 Years
				public void getPreviousAddDurationYears() {

					specifyHere = (EditText) findViewById(R.id.etPreviousAddressYears);
					vPreviousAddressYears = specifyHere.getText().toString();
					methods md = new methods();
					md.editorSharePreferences(this, "dPreviousAddressYears",
							vPreviousAddressYears);
				}

				public void getPreviousAddDurationYearsNull() {

					
					methods md = new methods();
					md.editorSharePreferences(this, "dPreviousAddressYears",
							null);
				}

				public void setPreviousAddDurationYears() {

					specifyHere = (EditText) findViewById(R.id.etPreviousAddressYears);
					methods md = new methods();
					specifyHere.setText(md.retriveSharePreference(this,
							"vPreviousAddressYears",
							"dPreviousAddressYears"));
				
				}
				
				
				// get customer resident duration months for not more then 3 Years
				public void getPreviousAddDurationMonths() {

					specifyHere = (EditText) findViewById(R.id.etPreviousAddressMonths);
					vPreviousAddressMonths = specifyHere.getText().toString();
					methods md = new methods();
					md.editorSharePreferences(this, "dPreviousAddressMonths",
							vPreviousAddressMonths);
				}

				public void getPreviousAddDurationMonthsNull() {

					
					methods md = new methods();
					md.editorSharePreferences(this, "dPreviousAddressMonths",
							null);
				}

				public void setPreviousAddDurationMonths() {

					specifyHere = (EditText) findViewById(R.id.etPreviousAddressMonths);
					methods md = new methods();
					specifyHere.setText(md.retriveSharePreference(this,
							"vPreviousAddressMonths",
							"dPreviousAddressMonths"));
				
				}

}
